package net.zoneland.knowledge.dao;

import net.zoneland.knowledge.model.VirtualGroup;
import net.zoneland.knowledge.model.VirtualGroupName;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

/**
 * 虚拟群组相关数据接口.
 * @author bcc
 */
@Mapper
public interface VirtualGroupMapper {

    /**
     * 查询我的群组.
     * @param uid 用户id
     * @return 群组名称列表
     */
    @Select({
            "<script>",
            "select id, group_name",
            "FROM aitk_virtual_group_name ",
            "WHERE creator_user_id = #{uid,jdbcType=VARCHAR}",
            "</script>"
    })
    @Results({
            @Result(column = "ID", property = "id", jdbcType = JdbcType.VARCHAR, id = true),
            @Result(column = "group_name", property = "groupName", jdbcType = JdbcType.VARCHAR)
    })
    List<VirtualGroupName> queryGroupNameByUid(@Param("uid") String uid);

    /**
     * 根据群组ID获取群组成员.
     * @param groupId 群组id
     * @return 群组人员信息.
     */
    @Select({
            "<script>",
            "select ID, MEMBER_TYPE,DISPLAY_NAME,OA_ID,",
            "ORG_UUID,ORG_SHORT_NAME",
            "FROM aitk_virtual_group ",
            "WHERE group_name_id = #{groupId,jdbcType=VARCHAR}",
            "ORDER BY order_num asc",
            "</script>"
    })
    @Results({
            @Result(column = "ID", property = "id", jdbcType = JdbcType.VARCHAR, id = true),
            @Result(column = "MEMBER_TYPE", property = "memberType", jdbcType = JdbcType.VARCHAR),
            @Result(column = "DISPLAY_NAME", property = "displayName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "OA_ID", property = "oaId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "ORG_UUID", property = "orgUUID", jdbcType = JdbcType.VARCHAR),
            @Result(column = "ORG_SHORT_NAME", property = "orgShortName", jdbcType = JdbcType.VARCHAR)
    })
    List<VirtualGroup> queryGroupMemberByGroupId(@Param("groupId") String groupId);
}
